// pages/JX/shouye/shouye.js
import S_request from '../../../utils/requestService.js';
import CONFIG from '../../../config.js';
const app = getApp()
Page({

  /**
   * 页面的初始数据
   */
  data: {
    username: '',
    mobile: '',
    wxqq: '',
    detail: '',
    isShow: false,
    isShowArea:true,
  },

  /**
   * 生命周期函数--监听页面加载
   */
  onLoad: function(options) {

  },
  nameInputEvent: function(e) {
    this.setData({
      username: e.detail.value
    })
  },
  mobileInputEvent: function(e) {
    this.setData({
      mobile: e.detail.value
    })
  },
  wxInputEvent: function(e) {
    this.setData({
      wxqq: e.detail.value
    })
  },
  detailInputEvent: function(e) {
    this.setData({
      detail: e.detail.value
    })
  },
  commitAddr: function() {
    let title = '';
    if (this.data.username == '') {
      title = '赞助商名字不能为空'
      this.showToast(title)
    } else if (this.data.mobile == '') {
      title = '手机号不能为空'
      this.showToast(title)
    } else if (this.data.mobile.length < 11) {
      title = '手机号格式不正确'
      this.showToast(title)
    } else if (this.data.wxqq == '') {
      title = '微信/QQ号不能为空'
      this.showToast(title)
    } else if (this.data.detail == '') {
      title = '简介不能为空'
      this.showToast(title)
    } else {
      S_request.jx.getSYInfo(this.data.username, this.data.mobile, this.data.wxqq, this.data.detail, (result) => {
        this.setData({
          isShow: true,
          modalDealIdx: 1,
          isShowArea:false
        })
      })
    }
  },
  closeBtnAc: function() {
    this.setData({
      isShow: false,
      modalDealIdx: 0,
      isShowArea: true,
      username: '',
      mobile: '',
      wxqq: '',
      detail: ''
    })
    setTimeout(function () {
      wx.navigateBack({})
    }, 500)
  },
  showToast: function(title) {
    wx.showToast({
      title: title,
      icon: 'none',
      duration: 2000
    })
  },
  formSubmit: function (e) {
    let formId = e.detail.formId;
    console.log('form发生了submit事件，携带数据为：', e.detail.value + ", " + e.detail.formId)
    let param = 'formId=' + formId;
    S_request.jx.tongJiNum(-1, param, (result) => {
      console.log("data====" + result);
    })
  },
  /**
   * 生命周期函数--监听页面初次渲染完成
   */
  onReady: function() {

  },

  /**
   * 生命周期函数--监听页面显示
   */
  onShow: function() {

  },

  /**
   * 生命周期函数--监听页面隐藏
   */
  onHide: function() {

  },

  /**
   * 生命周期函数--监听页面卸载
   */
  onUnload: function() {

  },

  /**
   * 页面相关事件处理函数--监听用户下拉动作
   */
  onPullDownRefresh: function() {

  },

  /**
   * 页面上拉触底事件的处理函数
   */
  onReachBottom: function() {

  },

  /**
   * 用户点击右上角分享
   */
  onShareAppMessage: function() {
    wx.showShareMenu({
      withShareTicket: false,
      success: function() {}
    });
    let obj = { 'pagepath': CONFIG.SHARE.path }
    S_request.jx.recordShare("-1", obj);
    return {
      title: CONFIG.SHARE.title,
      path: CONFIG.SHARE.path,
      imageUrl: CONFIG.SHARE.imageUrl,
      success: (res) => { //新版不走回调
        console.log("分享成功")
      }
    }
  }
})